<%@ page contentType="text/html;charset=UTF-8"%>
<%@include file="../../common/sessionValidate.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
  <head>
    <title>T_product信息维护</title>
    <%@ include file="../../common/meta.jsp"%>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
	<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen"  id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
  </head>
  <style>
	hr {
	    margin-top:1px;
	    border-bottom: 1px solid #1BBC9B;
	}
  </style>
  <body>
  <div class="" style="margin-right:2px;padding-right:1px;">

    <!--------------------------查询条件表格  start----------------------------->
  	<form class="form-horizontal" name="form1" id="form1">
	<div class="panel panel-primary" id="cxDiv">
	  <div class="panel-heading  " >
      	<i class='icon-filter'></i>&nbsp;查询内容
        <span class="text-right pull-right">
        	<button type="button" class=" btn btn-success btn-xs img-rounded"  onclick="Search(0)"><i class="icon-search"></i>&nbsp;查询</button>&nbsp;
            <button type="reset" class=" btn btn-success btn-xs img-rounded"  > <span class="icon-retweet"></span>&nbsp;重置</button>&nbsp;
            <button type="button" class=" btn btn-success btn-xs img-rounded" id="shButton" >&nbsp;<span id="qhDiv" class="icon-chevron-up"></span>&nbsp;</button>
            <input type="hidden" name="process_code" id="process_code" value="SixProcess">
        </span>
	  </div>
	  <div class="panel-body" id="shDiv" class="panel-collapse collapse in">
	      <div class="col-xs-4">
	          <div class="form-group">
	              <label class="control-label col-xs-6">目录1级</label>
	              <div class="col-xs-6">
	              	<select id="product_id1" name="product_id1" onChange="init2()" type="text" class="form-control">
						<option value="">---请选择---</option>
	              	</select>
	              	<input type="hidden" name="pid" id="pid" value="" />
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-4">
	          <div class="form-group">
	              <label class="control-label col-xs-6">目录2级</label>
	              <div class="col-xs-6">
	              	<select  id="product_id2" name="product_id2" onChange="init3()"  type="text" class="form-control">
						<option value="">---请选择---</option>
	              	</select>
	              </div>
	          </div>
	      </div>

	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6">名称</label>
	              <div class="col-xs-6">
	              	<input name="pname" type="text" class="form-control">
	              </div>
	          </div>
	      </div>

<!--
	      <div class="col-xs-4">
	          <div class="form-group">
	              <label class="control-label col-xs-6">目录3级</label>
	              <div class="col-xs-6">
	              	<select  id="product_id3" name="product_id3" onChange="setSanji()" type="text" class="form-control">
						<option value="">---请选择---</option>
	              	</select>

	              </div>
	          </div>
	      </div>


	  	 <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-5">product_id</label>
	              <div class="col-xs-7">
	              	<input name="product_id" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	  	 <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-5">开始时间</label>
	              <div class="col-xs-7">
	              	<input name="startdate" id="startdate" type="text" class="form-control" onclick='SelectDate(this)' readonly='true'>
	              </div>
	          </div>
	      </div>
	  	 <div class="col-xs-3 ">
	          <div class="form-group">
	              <label class="control-label col-xs-5">截止时间</label>
	              <div class="col-xs-7">
	              	<input name="enddate" id="enddate" type="text" class="form-control" onclick='SelectDate(this)' readonly='true'>
	              </div>
	          </div>
	      </div>

	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6">备注</label>
	              <div class="col-xs-6">
	              	<input name="pmemo" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6">级别</label>
	              <div class="col-xs-6">
	              	<input name="level" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6">状态</label>
	              <div class="col-xs-6">
	              	<input name="status" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6"> ext1</label>
	              <div class="col-xs-6">
	              	<input name="ext1" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6"> ext2</label>
	              <div class="col-xs-6">
	              	<input name="ext2" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6"> ext3</label>
	              <div class="col-xs-6">
	              	<input name="ext3" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6">插入时间</label>
	              <div class="col-xs-6">
	              	<input name="inserttime" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6">更新时间</label>
	              <div class="col-xs-6">
	              	<input name="updatetime" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6">操作人</label>
	              <div class="col-xs-6">
	              	<input name="creater" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3">
	          <div class="form-group">
	              <label class="control-label col-xs-6">更新人</label>
	              <div class="col-xs-6">
	              	<input name="updater" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	       -->

	  </div>
	</div>
    </form>
    <!-- -->
    <!--------------------------查询条件表格end------------------------------------->

    <!--------------------------信息列表：带表格面板  start--------------------------------->
	<div class="panel panel-primary">
	  <div class="panel-heading clearfix" >
	  	 <i class='icon-reorder'></i>&nbsp; 商品种类数据列表
	  	 <span class="text-right pull-right ">
            <a href="<%=basePath%>t_product/toT_productCurd?oplx=add" class="text-danger"><i class='icon-plus'></i>&nbsp;新增</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="toEdits()" class="text-danger"><i class='icon-pencil'>&nbsp;修改</i></a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="toViews()"  class="text-danger"><i class='icon-table'></i>&nbsp;查看</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="getDel()" class="text-danger"><i class='icon-minus'></i>&nbsp;删除</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="Search(0)" class="text-danger btn-sm"><i class='icon-refresh'></i>&nbsp;刷新</a>&nbsp;&nbsp;
            <a href="#" onclick="showOrHidden()" class="text-danger btn-sm"><span id="fsDiv" class='glyphicon glyphicon-resize-full'></span></a>
	     </span>
	  </div>
	  <div class="panel-body">
	    <p>每页显示<select id="pageSize" class=" label-primary" onchange="Search(0)">
		  <option value="10" >10</option>
		  <option value="20">20</option>
		  <option value="30">30</option>
		  <option value="50">50</option>
		  <option value="1000" >1000</option>

		 </select>条记录，&nbsp;&nbsp;&nbsp;&nbsp;共有记录：<span id="totalCount" class="label label-primary">0</span> 条，总页数：<span id="totalPageNo" class="label label-primary">0</span>页。
        </p>
	    <table id="grid" class="table table-condensed table-striped table-bordered table-hover" class="sortable" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
	     <thead id="grid_head">
	      <tr>
	          <th onclick="" class="table-checkbox" ><input class="group-checkable" name="batchSelectedAll" id="batchSelectedAll" type="checkbox" onclick="selectAll()"></th>
	          <th onclick="sortTableT.sort('grid',0,'String')">主键</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">名称</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">备注</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">上级id</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">级别</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">状态</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">顺序</th>
	          <th style="width:150px">操作</th>
	      </tr>
	     </thead>
	     <tbody id="grid_body"></tbody>
	    </table>
	    <div class="paging-toolbar">
	   		<ul class="pager" style='margin-bottom:5px;' id='grid_paging'></ul>
	    </div>
	  </div>
    </div>
    <!--------------------------信息列表：带表格面板 end------------------------------------>

  </div>
  </body>
</html>

<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!--<script src="<%=basePath%>js/jquery-1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js" ></script>
<script src="<%= basePath %>js/calendar.js" ></script>

<script type="text/javascript">
$().ready(function(){
	//1、初始化数据显示
	Search(0);

	//2、隐藏或者显示
    $("#shButton").click(function(){
    	$("#shDiv").toggle();
    	$("#qhDiv").toggleClass("icon-chevron-up icon-chevron-down");
  	});

	//初始化商品目录
    init1();

}) //end funciton read;

//根据查询条件，查询列表数据并显示
function Search(startIndex){
	var pageSize = 10; //document.getElementById("pageSize").value;
	var condition = $("#form1").serialize();
	var url = "<%=basePath%>t_product/getAllT_productByPid?startIndex="+startIndex+"&pageSize="+pageSize+"&"+condition+"&time="+Math.random();
	//alert(url);
	$.ajaxSettings.async = false; //设置为同步，否则会有部分数据没出来
	$.getJSON(url, function (data){
    	//alert("data.totalCount="+data.totalCount);
		//$("#pageSize").html(data.pageSize);
		$("#totalCount").html(data.totalCount);
		$("#totalPageNo").html(data.totalPageNo);
		$("#grid_body").html("");
		//alert("data.items json to string ="+JSON.stringify(data.items));

		//1、表格行内容输出
	    $.each(data.items, function(i,item){
	    	//alert("item.product_id="+item.product_id);
	    	//alert("item json to string ="+JSON.stringify(item));
	    	if(item.product_id!=0){ //如果不是根，才显示，根不显示。
				var str="<tr>";
				str+="<td><input class='checkboxes' name='batchSelected' id='batchSelected' type='checkbox' value='"+item.product_id+"'></td>";
				str+="<td>"+doNull(item.product_id)+"</td>";
				if(item.level==0){
					//str+="<td><i class='icon-home'></i>"+doNull(item.pname)+"</i></td>";
				}else if(item.level==1){
					str+="<td><i class='icon-folder-open-alt'></i>"+doNull(item.pname)+"</td>";
				}else if(item.level==2){
					str+="<td>&nbsp;&nbsp;&nbsp;&nbsp;<i class='icon-folder-open-alt'></i>"+doNull(item.pname)+"</td>";
				}else if(item.level==3){
					str+="<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i class='icon-folder-close-alt'></i>"+doNull(item.pname)+"</td>";
				}
				str+="<td>"+doNull(item.pmemo)+"</td>";
				str+="<td>"+doNull(item.pid)+"</td>";
				var levelmsg ="";
				if(item.level!=null&&item.level!=""){
					if(item.level=="1"){
						levelmsg = "<span class='label label-primary'>1级</span>";
					}else if(item.level=="2"){
						levelmsg = "<span class='label label-primary'>2级</span>";
					}else if(item.level=="3"){
						levelmsg = "<span class='label label-primary'>3级</span>";
					}else if(item.level=="4"){
						levelmsg = "<span class='label label-primary'>4级</span>";
					}else if(item.level=="4"){
					levelmsg = "<span class='label label-primary'>5级</span>";
					}
				}
				str+="<td>"+levelmsg+"</td>";
				var statusmsg = "";
				if(item.status!=null&&item.status!=""){
					if(item.status=="1"){
						statusmsg="<span class='label label-primary'>有效</span>";
					}else{
						statusmsg="<span class='label label-danger'>无效</span>";
					}
				}
				str+="<td>"+ statusmsg +"</td>";
				str+="<td>"+doNull(item.showseq)+"</td>";
				str+="<td>&nbsp;&nbsp;";
				str+="<a href='<%=basePath%>t_product/toT_productCurd?oplx=view&id="+item.product_id+"' class='text-danger'>&nbsp;&nbsp;<span class='glyphicon glyphicon-search' style='color:rgb(0, 128, 255)'></span>&nbsp;&nbsp;</a>";
				str+="<a href='<%=basePath%>t_product/toT_productCurd?oplx=edit&id="+item.product_id+"' class='text-danger'>&nbsp;&nbsp;<span class='icon-pencil'  style='color:rgb(0, 128, 255)'></span>&nbsp;&nbsp;</a>";
				//str+="<a href='javascript:del("+item.product_id+")' class='text-danger'>&nbsp;&nbsp;<span class='icon-remove' style='color:rgb(0, 128, 255)'></span></a>&nbsp;&nbsp;";
				str+="</td>";
				str+="</tr>";
				$("#grid_body").append(str);
	    	}
		});//end each data;

		//2、分业处理
		var element = $("#grid_paging");
		if(data.totalCount>0){
			    //第二种处理分页方案，直接生成分页html内容，然后.html()到目标对象；
	        var pageHtml ="";
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.firstIndex+')">首页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.previousIndex+')">上一页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " >当前第  '+data.currentPageNo+' 页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.nextIndex+')">下一页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.lastIndex+')">尾页</button></li>';
			element.html(pageHtml);
		}else{
			element.html("");
		}
    })//end getJSON;
}

//通过选择单条记录，点击‘修改‘按钮进行查看
function toEdits(){
   	var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
   	if(id!=false){
		self.location= "<%=basePath%>t_product/toT_productCurd?oplx=edit&id="+id+"&time="+Math.random();
   	}
}

//通过选择单条记录，点击‘查看‘按钮进行查看
function toViews(){
   	var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
   	if(id!=false){
		self.location= "<%=basePath%>t_product/toT_productCurd?oplx=view&id="+id+"&time="+Math.random();;
   	}
}

//通过选择单条记录，点击‘删除‘按钮进行查看
function getDel(){
   	var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
   	if(id!=false){
   		del(id);
   	}
}

//删除函数
function del(id){
   	var url = "<%=basePath%>t_product/delT_product?id=" + id+"&time="+Math.random();
 	bootbox.confirm({
		size: 'small',
		buttons: {
	            confirm: {
	                label: ' 删除 ',
	                className: 'btn btn-sm btn-danger'
	            },
	            cancel: {
	                label: '   取消     ',
	                className: 'btn btn-success btn-sm'
	            }
        },
        message: '您确认要删除选中的记录？',
        callback: function(result) {
            if(result) {if(result){ myDel(url);}}
        },
        title:'删除记录提示：',
        className:' '
	})
}

//初始化商品一级目录
function init1(){
	//1、初始化数据显示
	//var selectItemsOptions; //设置在这里，为了遍历生成js时使用，在数据获取时，先保存在sdata，然后在后面使用。

	//清空所有下拉
	$("#product_id1").empty();
	$("#product_id2").empty();
	$("#product_id3").empty();

	$("#product_name1").html("");
	$("#product_name2").html("");
	$("#product_name3").html("");

	$("#product_id1").append("<option value=''></option>");
	$("#product_id2").append("<option value=''></option>");
	$("#product_id3").append("<option value=''></option>");

	//初始化 上级菜单及id的select options；
    var purl = "<%=basePath%>t_product/getAllT_productByPid?product_id=0&level=1&startIndex=0&pageSize=1000&time="
								+ Math.random();
	//alert(purl);
	$.ajaxSettings.async = false; //设置为同步，否则会有部分数据没出来
	$.getJSON(purl, function(data) {
		//alert("data="+data.items);
		$.each(data.items, function(i, item) {
			$("#product_id1").append(
					"<option value='"+item.product_id+"'><p class='icon-folder-open-alt'>"
							+ item.pname
							+ "</p></option>");
		});//end each
	}); //end getJson

}
function init2() {
	//先清空本级及下级option；
	$("#product_id2").empty();
	$("#product_id3").empty();
	$("#product_id2").append("<option value=''></option>");
	$("#product_id3").append("<option value=''></option>");

	//$("#product_name2").val("");
	//$("#product_name3").val("");

	var pid = $("#product_id1").val();
	//var product_name1 = "&nbsp;&nbsp;"+$("#product_id1  option:selected").text()+">>";
	var product_name1 = $("#product_id1  option:selected").val();
	//alert(product_name1);
	//$("#product_name1").val(product_name1);
	$("#pid").val(product_name1);
	//alert(pid);
	//初始化 2级菜单及id的select options；
	var purl2 = "<%=basePath%>t_product/getAllT_productByPid?pid="+pid+"&level=2&startIndex=0&pageSize=1000&time="+Math.random();
	//alert("purl2="+purl2);
	//$.ajaxSettings.async = false; //设置为同步，否则会有部分数据没出来
	$.getJSON(purl2, function (data) {
		//alert("data2="+data.items);
		$.each(data.items, function(i,item){
			//alert("option="+item.pname);
	    	$("#product_id2").append("<option value='"+item.product_id+"'><p class='icon-folder-open-alt'>"+item.pname+"</p></option>");
		});//end each
	}); //end getJson
}

function init3(){
	//先清空本级及下级option；
	$("#product_id3").empty();
	$("#product_id3").append("<option value=''></option>");

	//$("#product_name2").val("");
	//$("#product_name3").val("");

	var pid = $("#product_id2").val();
	//var product_name2 = "&nbsp;&nbsp;"+ $("#product_id2  option:selected").text()+">>";
	var product_name2 = $("#product_id2  option:selected").val();
	//alert(product_name2);
	//$("#product_name2").val(product_name2);
	$("#pid").val(product_name2);

	//alert("init3 pid="+pid);
	//初始化 2级菜单及id的select options；
	var purl3 = "<%=basePath%>t_product/getAllT_productByPid?pid="+pid+"&level=3&startIndex=0&pageSize=1000&time="+Math.random();
	//alert("purl3="+purl3);
	//$.ajaxSettings.async = false; //设置为同步，否则会有部分数据没出来
	$.getJSON(purl3, function (data) {
		//alert("data3="+data.items);
		$.each(data.items, function(i,item){
			//alert("option3="+item.pname);
	    	$("#product_id3").append("<option value='"+item.product_id+"'><p class='icon-folder-open-alt'>"+item.pname+"</p></option>");
		});//end each
	}); //end getJson
}

//设置第三级目录名称值
function setSanji(){
	$("#product_name3").val("");

	var pid = $("#product_id3").val();
	//var product_name3 = "&nbsp;&nbsp;"+ $("#product_id  option:selected").text()+">>";
	var product_name3 = $("#product_id3  option:selected").val();
	//alert(product_name3);
	//$("#product_name3").val(product_name3);
	$("#pid").val(product_name3);
}

</script>
